home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / drum_ed.c < prev    next >
C/C++ Source or Header  |  1995-02-19  |  4KB  |  132 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; drum_ed.c : drum editor
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <string.h>
  22. #include <gemfast.h>
  23. #include <aesbind.h>
  24. #include "gm/gem_man.h"
  25. #include "eked-m1.h"
  26. #include "defs.h"
  27. #include "types.h"
  28. #include "externs.h"
  29.  
  30. typedef struct {
  31.   int ob_number;
  32.   PARA_TYPE type;
  33. } DPARAMETER;
  34.  
  35. #define DT_SIZE        6
  36. static DPARAMETER drum_table[] =
  37. {
  38.   {D_SOUND,    DSND},
  39.   {D_KEY,    DKEY},
  40.   {D_PAN,    CPAN},
  41.   {D_TUNE,    S120},
  42.   {D_LEVEL,    SN50},
  43.   {D_DECAY,    SN50}
  44. };
  45.  
  46. OBJECT *drum;
  47. OBJECT *drum_head;
  48.  
  49. static void display(int x_pos, int y_pos, GRECT *clip, long usr_val);
  50. static int action(int handle, E_TYPE type, void *event,
  51.                   int x_pos, int y_pos, long usr_val);
  52.  
  53. int de_window(char *title, BYTE *kit)
  54. {
  55.   int t;
  56.  
  57.   rm_gaddr(R_TREE, DRUM, &drum);
  58.   rm_gaddr(R_TREE, DRUM_HEAD, &drum_head);
  59.   t = wm_open(NAME | CLOSER | FULLER | MOVER | SIZER |
  60.               UPARROW | DNARROW | VSLIDE |
  61.               LFARROW | RTARROW | HSLIDE,
  62.               (GRECT *) 0, title,
  63.               drum[0].ob_width, 31 * drum[0].ob_height,
  64.               char_w, drum[0].ob_height, &display, &action, (long) kit);
  65.   if(t < 0){
  66.     fm_alert(1, WINDOW_ALERT);
  67.     return 0;
  68.   }
  69.   return t;
  70. }
  71.  
  72. static void display(int x_pos, int y_pos, GRECT *clip, long usr_val)
  73. {
  74.   int i, j, e, h = drum[0].ob_height;
  75.   BYTE *data;
  76.  
  77.   i = (clip->g_y - y_pos) / h - 1;
  78.   if(i < 0){
  79.     i = 0;
  80.     drum_head[0].ob_x = x_pos;
  81.     drum_head[0].ob_y = y_pos;
  82.     objc_draw(drum_head, 0, MAX_DEPTH,
  83.               clip->g_x, clip->g_y, clip->g_w, clip->g_h);
  84.   }
  85.   e = (clip->g_y + clip->g_h - 1 - y_pos) / h - 1;
  86.   if(e >= 0){
  87.     drum[0].ob_x = x_pos;
  88.     drum[0].ob_y = y_pos + i * h;
  89.     data = ((BYTE *) usr_val) + i * 7;
  90.     for(; i <= e; i++){
  91.       drum[0].ob_y += h;
  92.       ((char *) drum[D_NUMBER].ob_spec)[0] = '0' + i / 10;
  93.       ((char *) drum[D_NUMBER].ob_spec)[1] = '0' + i % 10;
  94.       for(j = 0; j < DT_SIZE; j++)
  95.         para_fill(drum + drum_table[j].ob_number, drum_table[j].type, data++);
  96.       data++;
  97.       objc_draw(drum, 0, MAX_DEPTH,
  98.                 clip->g_x, clip->g_y, clip->g_w, clip->g_h);
  99.     }
  100.   }
  101. }
  102.  
  103. static int action(int handle, E_TYPE type, void *event,
  104.                   int x_pos, int y_pos, long usr_val)
  105. {
  106.   int i, j, h = drum[0].ob_height, m_x, m_y, ob;
  107.  
  108.   switch(type){
  109.   case E_CLEANUP:
  110.     ge_drumexit(handle);
  111.     break;
  112.   case E_CLICK:
  113.     m_x = ((CLICK *) event)->m_x;
  114.     m_y = ((CLICK *) event)->m_y;
  115.     i = (m_y - y_pos) / h;
  116.     if(i == 0)
  117.       break;
  118.     drum[0].ob_x = x_pos;
  119.     drum[0].ob_y = y_pos + h * i;
  120.     ob = objc_find(drum, 0, MAX_DEPTH, m_x, m_y);
  121.     for(j = 0; j < DT_SIZE; j++){
  122.       if(drum_table[j].ob_number == ob){
  123.         para_edit(handle, drum, ob, drum_table[j].type, -1, -1,
  124.                   ((BYTE *) usr_val) + (i - 1) * 7 + j);
  125.         break;
  126.       }
  127.     }
  128.     break;
  129.   }
  130.   return R_NORMAL;
  131. }
  132.